package com.rentcars.controller;

import com.github.pagehelper.PageInfo;
import com.rentcars.entity.Clientuser;
import com.rentcars.entity.Credit;
import com.rentcars.service.CreditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 任梦强
 * @date 2021.3.3
 */
@RestController
public class CreditController {
    @Autowired
    private CreditService creditService;

    @RequestMapping("credit")
    public PageInfo<Credit> selectAllCredit(Credit credit,Integer curr,Integer pageSize){
        PageInfo<Credit>creditPageInfo=creditService.selectAllCredit(credit,curr,pageSize);
        return creditPageInfo;
    }

    @RequestMapping("/credit-list")
    public ModelAndView toCredit(){
        return new ModelAndView("credit-list");
    }

    @RequestMapping("creditAdd")
    public int insertSelective(Credit credit){
        return creditService.insertSelective(credit);

    }

    @RequestMapping("/credit-add")
    public ModelAndView toAdd(){
        return new ModelAndView("credit-add");
    }


    @RequestMapping("/creditPage")
    public ModelAndView findUser(String cid){
        Credit credit=creditService.selectCreditById(cid);
        Map<String,Object> map=new HashMap<>();
        map.put("aaa",credit);
        return new ModelAndView("credit-edit",map);
    }

    @RequestMapping("/creditEdit")
    public int editCredit(Credit credit){
        return creditService.updateCredit(credit);

    }

    /**
     * 根据ID删除信息
     * @param cid
     * @return
     */
    @RequestMapping("/creditDel")
    public int deleteByCid(String cid){
        return creditService.deleteByCid(cid);
    }

    @RequestMapping("/deleteCredit")
    public int delClientUser(@RequestParam String creditCid){
        List<String> cidList= Arrays.asList(creditCid.split(","));
        return creditService.delCredit(cidList);

    }

    public CreditService getCreditService() {
        return creditService;
    }

    public void setCreditService(CreditService creditService) {
        this.creditService = creditService;
    }
}
